//
//  detailViewController.swift
//  Reid
//
//  Created by Fizgrad Chen on 2022/5/1.
//

import UIKit
import WebKit

class detailViewController: UIViewController {
    
    var count: Int?
    var flow: Double?
    var time: Double?
    var dist: Double?
    var englishName: String?
    @IBOutlet weak var blueimage: UIImageView!
    @IBOutlet weak var greenimage: UIImageView!
    @IBOutlet weak var yellowimage: UIImageView!
    @IBOutlet weak var redimage: UIImageView!
    
    
    @IBOutlet weak var im2: UIImageView!
    @IBOutlet weak var im1: UIImageView!
    @IBOutlet weak var im3: UIImageView!
    @IBOutlet weak var im4: UIImageView!
    @IBOutlet weak var countLabel: UILabel!
    @IBOutlet weak var flowLabel: UILabel!
    @IBOutlet weak var timeLabel: UILabel!
    @IBOutlet weak var distLabel: UILabel!
    
    @IBOutlet weak var webPage: WKWebView!
    
    override func viewDidLoad() {

        super.viewDidLoad()
        
        im1.layer.cornerRadius = im1.frame.size.width/10
        im1.layer.masksToBounds = true
        
        im2.layer.cornerRadius = im2.frame.size.width/10
        im2.layer.masksToBounds = true

        im3.layer.cornerRadius = im3.frame.size.width/10
        im3.layer.masksToBounds = true
        
        im4.layer.cornerRadius = im4.frame.size.width/10
        im4.layer.masksToBounds = true
        
        blueimage.layer.cornerRadius = blueimage.frame.size.width/10
        blueimage.layer.masksToBounds = true
        
        greenimage.layer.cornerRadius = greenimage.frame.size.width/10
        greenimage.layer.masksToBounds = true

        yellowimage.layer.cornerRadius = yellowimage.frame.size.width/10
        yellowimage.layer.masksToBounds = true
        
        redimage.layer.cornerRadius = redimage.frame.size.width/10
        redimage.layer.masksToBounds = true
        
        
  // Do any additional setup after loading the view.
    }

    override func viewDidAppear(_ animated: Bool) {

        countLabel.text = "\(count!)"
        flowLabel.text = "\(flow!)"
        timeLabel.text = "\(time!)"
        distLabel.text = "\(dist!)"
        
        let myURL = Bundle.main.url(forResource: englishName, withExtension: "html")
        let request = URLRequest(url: myURL!)
        
        webPage.load(request)
        webPage.loadFileURL(myURL!, allowingReadAccessTo: Bundle.main.bundleURL)
        webPage.contentMode = .scaleToFill
      
    }
    @IBAction func changeMode(_ sender: Any) {

        let myURL = Bundle.main.url(forResource: englishName!+"Time", withExtension: "html")
        let request = URLRequest(url: myURL!)
        
        webPage.load(request)
        webPage.loadFileURL(myURL!, allowingReadAccessTo: Bundle.main.bundleURL)
        webPage.contentMode = .scaleToFill
    }
    @IBAction func changeMode2(_ sender: Any) {

        let myURL = Bundle.main.url(forResource: englishName, withExtension: "html")
        let request = URLRequest(url: myURL!)
        
        webPage.load(request)
        webPage.loadFileURL(myURL!, allowingReadAccessTo: Bundle.main.bundleURL)
        webPage.contentMode = .scaleToFill
    }
    @IBAction func close(_ sender: Any) {
        dismiss(animated: true)
    }
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
